﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Bzure.Common.Configuration.AppConfiguration;

namespace Bzure.Common.HttpAspects.Configuration
{
    public class AspectConfig : ReflectConfigSection
    {
        static Dictionary<string, IHttpAspect> handlers = new Dictionary<string, IHttpAspect>();
        public override string BlockName
        {
            get { return "aspect"; }
        }
        public IHttpAspect GetAspectHandler()
        {
            IHttpAspect handler = default(IHttpAspect);
            if (!this.Single)
            {
                handlers.TryGetValue(this.Name, out handler);
            }
            if (handler == default(IHttpAspect))
            {
                handler = new DefaultConfigObjectFactory<IHttpAspect>().CreateInstance(this);
                if (handler != default(IHttpAspect))
                    handlers[this.Name] = handler;
            }
            return handler;
        }
    }
}
